package com.nineclock.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.nineclock.common.utils.BeanHelper;
import com.nineclock.system.dto.SysCommonIndustryDTO;
import com.nineclock.system.mapper.SysCommonIndustryMapper;
import com.nineclock.system.pojo.SysCommonIndustry;
import com.nineclock.system.service.SysCommonIndustryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
@Transactional
public class SysCommonIndustryServiceImpl implements SysCommonIndustryService {
    @Autowired
    private SysCommonIndustryMapper commonIndustryMapper;
    //获取行业
    @Override
    public List<SysCommonIndustryDTO> getParent(String parentId) {
        //查询所有父行业(Id为大写字母)
        if (!StringUtils.isEmpty(parentId)) {
            LambdaQueryWrapper<SysCommonIndustry> wrapper = new LambdaQueryWrapper<>();
            wrapper.in(SysCommonIndustry::getParentId, parentId);
            List<SysCommonIndustry> commonIndustries = commonIndustryMapper.selectList(wrapper);

            return BeanHelper.copyWithCollection(commonIndustries, SysCommonIndustryDTO.class);
        }

        List<SysCommonIndustry> commonIndustries = commonIndustryMapper.selectList(null);
        return BeanHelper.copyWithCollection(commonIndustries, SysCommonIndustryDTO.class);

    }
}
